/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.qp.smsmarketing.dao;

import com.qp.smsmarketing.dao.abstractdao.AbstractDAO;
import com.qp.smsmarketing.dao.abstractdao.Hib;
import com.qp.smsmarketing.entity.Papel;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author waldenilson
 */
public class PapelDAO extends AbstractDAO {

    public PapelDAO()
    {
        super.entityManager = Hib.getSessionFactory();
    }

    public List buscarTodos() {
        return findAllRows("Papel");
    }

    public boolean salvarObj(Object o) {
        return salvar(o);
    }

    public boolean atualizarDados(Object o) {
        return atualizar(o);
    }
     public Object buscarRegistro(int id) {
        return findOne("Papel", id);
    }

    public Papel buscarRegistro(String nome) {

        query = entityManager.createQuery("SELECT e FROM Papel e WHERE e.nomeRole = :nome");

        query.setParameter("nome", nome);

        List<Papel> lp = query.getResultList();
        if(lp.isEmpty())
            return null;
        else
            return lp.get(0);
    }
}
